<?php
chdir("../../");
require_once getcwd(). "/simpletest/autorun.php";
require_once getcwd(). "/service.impl/UserManager.php";
require_once getcwd(). "/simpletest/unit_tester.php";
require_once getcwd(). "/models/User.php";

class TestUserManager extends UnitTestCase {
	
	public function testMapping(){
		$user = new User("moonId");
		$mgr = new UserManager();
		$mgr->createModelRepoFromModel($user);
		$uRepo = $mgr->model;
		
		
		$this->assertEqual($user->uid,$uRepo->uid);
		$this->assertEqual($user->name,$uRepo->name);
		$this->assertEqual($user->login,$uRepo->login);
		$this->assertEqual($user->phoneToken,$uRepo->token);
		$this->assertEqual($user->access,$uRepo->password);
	}
	
	public function AtestInsert(){
		$user = new User("moonId");
		$mgr = new UserManager();
		$count = $mgr->insert($user);
		
		$this->assertEqual($count,1);
		
	}
	
	public function generateId(){
		$code = md5(uniqid(rand(), true));
		return substr($code, 0, 10);
	}
	
	public function testUpdate(){
		$user = new User("moonId");
		$user->login = $this->generateId();
		$mgr = new UserManager();
		
		$count = $mgr->update($user);
		$this->assertEqual($count,1);
		
	}
	
	public function testDelete(){
		$user = new User("moonId");
		$mgr = new UserManager();
		$count = $mgr->delete($user);
		$this->assertEqual($count,null);
	}
}

?>